package com.grow.greenhouse.controller;

import com.grow.greenhouse.utils.MqttUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/mqtt")
@RestController
public class TestMqttController {

    @Resource
    private MqttUtil mqttUtil;

    @PostMapping("/message")
    public String sendMsg(@RequestBody String message){
        //订阅发布主题
        String topic="$sys/098k43SLt4/d1/thing/property/post";
        mqttUtil.publish(topic,message,0);
        return "发送成功";
    }
}
